asynchHandler = new Object();

asynchHandler.http = "";
asynchHandler.eventSink = "";
asynchHandler.receivedData = "";
asynchHandler.IsBusy=false;

asynchHandler.sendHttpRequest = 
    function (method, url) {
       // Make sure we have a post method defined
       if (method.toUpperCase() != "POST"){
          // If not this is a get
          method = "GET";
       }

       this.http.open(method, url, true);

       //Register the call back here (could be over-ridden)
       this.http.onreadystatechange = this.InternalCallBack; 
       this.http.send(null);
    }

asynchHandler.InternalCallBack = 
    function (){
        // Call from the http objects (beware of stack pointer info)
        if (this.readyState == 4) {
            asynchHandler.receivedData = this.responseText;
            asynchHandler.IsBusy=false;
            asynchHandler.eventSink();
        }
    }
    
asynchHandler.getHttpObject = 
    function  () {
       var xmlhttp;
       xmlhttp = new XMLHttpRequest();
       return xmlhttp;
    }

asynchHandler.init = 
    function () {
        if (this.IsBusy == false){
            this.IsBusy = true;
            this.http = "";
            this.eventSink = "";
            this.receivedData = "";
            this.http = this.getHttpObject();
        }
        else {
            return "ASYNC_H_ERR_BUSY";
        }
    }

asynchHandler.setEventSink = 
    function (callbackFunction){
       this.eventSink = callbackFunction;
    }
